﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Core.Util;
using ZHDJ.WebPage;

namespace ZHDJ.Web.Log
{
    public partial class LogDetail : PortalPage
    {
        public string Para
        {
            get { return Request["Para"] ?? ""; }

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            CheckLogin(true);
            if (CurrentUser.LoginID != "admin")
            {
                Response.Clear();
                Response.Write("无权限");
                Response.End();
                return;
            }
            if (Para == "")
            {
                return;
            }
            if (ValidateHelper.IsDateTime(Para))
            {
                var path = Server.MapPath("~/Log/Error/" + Convert.ToDateTime(Para).ToString("yyyy-MM-dd") + ".log");
                var pathCopy = Server.MapPath("~/Log/Error/" + Convert.ToDateTime(Para).ToString("yyyy-MM-dd") + "copy.log");

                FileInfo file = new FileInfo(path);

                if (file.Exists)
                {
                    file.CopyTo(pathCopy, true);
                    Response.Clear();
                    Response.Write(System.Text.Encoding.Default.GetString(File.ReadAllBytes(pathCopy)));
                    File.Delete(pathCopy);
                    Response.End();
                   
                }
                else
                {
                    Response.Clear();
                    Response.Write("<HR COLOR=red>无日志</HR>");
                    Response.End();
                }

            }
            else
            {
                Response.Clear();
                Response.Write("");
                Response.End();
            }


        }
    }
}